﻿using StoryMaker.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace StoryMaker.Application
{
    /// <summary>
    /// Interaction logic for OpenStory.xaml
    /// </summary>
    public partial class OpenStory : Window
    {
        public OpenStory()
        {
            InitializeComponent();
            ViewModel = new OpenStoryViewModel();
            CommandBinding openBinding = new CommandBinding(ApplicationCommands.Open);
            openBinding.Executed += new ExecutedRoutedEventHandler(openBinding_Executed);
            openBinding.CanExecute += new CanExecuteRoutedEventHandler(openBinding_CanExecute);
            CommandBinding closeBinding = new CommandBinding(ApplicationCommands.Close);
            closeBinding.Executed += new ExecutedRoutedEventHandler(closeBinding_Executed);
            closeBinding.CanExecute += new CanExecuteRoutedEventHandler(closeBinding_CanExecute);
        }

        void closeBinding_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = ViewModel.SelectedStory != null;
        }

        void openBinding_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {

        }

        void closeBinding_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            this.DialogResult = false;
            this.Close();
        }

        void openBinding_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            this.DialogResult = true;
            this.Close();
        }

        public OpenStoryViewModel ViewModel
        {
            get;
            set;
        }
    }
}
